// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import UIKit

public struct ToolbarElement: Equatable {
    /// Icon name of the toolbar element
    let iconName: String?

    /// Title of the toolbar element
    let title: String?

    /// Badge name of the toolbar element
    let badgeImageName: String?

    /// Mask name of the badge's toolbar element
    let maskImageName: String?

    /// Indicated whether to use template mode or not for an image
    let templateModeForImage: Bool

    /// TODO: FXIOS-13949 Should investigate if there is a better way to do this
    let loadingConfig: LoadingConfig?

    /// Number of open tabs
    let numberOfTabs: Int?

    /// Whether the toolbar element can be interacted with
    let isEnabled: Bool

    /// Indicates whether the toolbar element's image should be flipped for right-to-left layout direction
    let isFlippedForRTL: Bool

    /// Indicates if the element is in the selected state and should be displayed as highlighted.
    let isSelected: Bool

    /// Indicates if the element has a custom color
    let hasCustomColor: Bool

    /// Indicates if the element has a highlighted color when tapping on it
    let hasHighlightedColor: Bool

    /// Title to display in the large content viewer
    let largeContentTitle: String?

    /// Indicates that there is an associated contextual hint
    let contextualHintType: String?

    /// Accessibility label of the toolbar element
    let a11yLabel: String

    /// Accessibility hint of the toolbar element
    let a11yHint: String?

    /// Accessibility identifier of the toolbar element
    let a11yId: String

    /// Name for the custom accessibility action
    let a11yCustomActionName: String?

    /// Action to be performed for custom accessibility action
    let a11yCustomAction: (() -> Void)?

    /// Indicates whether the toolbar element has a long press action or not
    /// this is only used to compare for equality as closures can't be compared
    let hasLongPressAction: Bool

    /// Closure that is executed when the toolbar element is tapped
    let onSelected: ((UIButton) -> Void)?

    /// Closure that is executed when the toolbar element is long pressed
    let onLongPress: ((UIButton) -> Void)?

    // We need this init as by default the init generated by the compiler for the struct will be internal and
    // can therefor not be used outside of the ToolbarKit
    public init(iconName: String? = nil,
                title: String? = nil,
                badgeImageName: String? = nil,
                maskImageName: String? = nil,
                templateModeForImage: Bool = true,
                loadingConfig: LoadingConfig? = nil,
                numberOfTabs: Int? = nil,
                isEnabled: Bool,
                isFlippedForRTL: Bool = false,
                isSelected: Bool = false,
                hasCustomColor: Bool = false,
                hasHighlightedColor: Bool = true,
                largeContentTitle: String? = nil,
                contextualHintType: String? = nil,
                a11yLabel: String,
                a11yHint: String?,
                a11yId: String,
                a11yCustomActionName: String? = nil,
                a11yCustomAction: (() -> Void)? = nil,
                hasLongPressAction: Bool,
                onSelected: ((UIButton) -> Void)?,
                onLongPress: ((UIButton) -> Void)? = nil) {
        self.iconName = iconName
        self.title = title
        self.badgeImageName = badgeImageName
        self.maskImageName = maskImageName
        self.templateModeForImage = templateModeForImage
        self.loadingConfig = loadingConfig
        self.numberOfTabs = numberOfTabs
        self.isEnabled = isEnabled
        self.isFlippedForRTL = isFlippedForRTL
        self.isSelected = isSelected
        self.hasCustomColor = hasCustomColor
        self.hasHighlightedColor = hasHighlightedColor
        self.largeContentTitle = largeContentTitle
        self.contextualHintType = contextualHintType
        self.onSelected = onSelected
        self.onLongPress = onLongPress
        self.a11yLabel = a11yLabel
        self.a11yHint = a11yHint
        self.a11yId = a11yId
        self.a11yCustomActionName = a11yCustomActionName
        self.a11yCustomAction = a11yCustomAction
        self.hasLongPressAction = hasLongPressAction
    }

    public static func == (lhs: ToolbarElement, rhs: ToolbarElement) -> Bool {
        lhs.iconName == rhs.iconName &&
        lhs.title == rhs.title &&
        lhs.badgeImageName == rhs.badgeImageName &&
        lhs.maskImageName == rhs.maskImageName &&
        lhs.templateModeForImage == rhs.templateModeForImage &&
        lhs.loadingConfig == rhs.loadingConfig &&
        lhs.numberOfTabs == rhs.numberOfTabs &&
        lhs.isEnabled == rhs.isEnabled &&
        lhs.isFlippedForRTL == rhs.isFlippedForRTL &&
        lhs.isSelected == rhs.isSelected &&
        lhs.hasCustomColor == rhs.hasCustomColor &&
        lhs.hasHighlightedColor == rhs.hasHighlightedColor &&
        lhs.largeContentTitle == rhs.largeContentTitle &&
        lhs.contextualHintType == rhs.contextualHintType &&
        lhs.hasLongPressAction == rhs.hasLongPressAction &&
        lhs.a11yLabel == rhs.a11yLabel &&
        lhs.a11yHint == rhs.a11yHint &&
        lhs.a11yId == rhs.a11yId &&
        lhs.a11yCustomActionName == rhs.a11yCustomActionName
    }
}
